﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class Gun : MonoBehaviour
{
    public float bulletSpeed = 20f;
    public Rigidbody2D rocket;
    private Animator anim;
    private PlayerControl pCtrl;
    // Start is called before the first frame update
    void Start()
    {
        pCtrl = transform.root.GetComponent<PlayerControl>();
        anim = transform.root.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1")){

            BattleManager.SendFire();

            GetComponent<AudioSource>().Play();
            anim.SetTrigger("Fire");//设置过渡到射击动画的触发器
            int i = Convert.ToInt16(!pCtrl.FaceR);
            Rigidbody2D bullet = Instantiate(rocket, transform.position, Quaternion.Euler(0, 0, 180f * i));
            bullet.velocity = new Vector2(bulletSpeed * (1 - 2 * i), 0);
        }
    }

}
